package com.hongtao3.hsync.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import com.hongtao3.hsync.Main;

public class FileButton extends JPanel {
	public FileButton(File f,ResourcesPanel owner){
		this.file=f;
		this.owner=owner;
		setToolTipText(f.getName());
		setLayout(new BorderLayout());
		init();
	}
	private void init(){
		setPreferredSize(new Dimension(70,50));
		add(new JLabel(new ImageIcon(Main.getResourcesImage(file.isDirectory()?"folder.png":"file.png"))),BorderLayout.NORTH);
       JLabel l=new JLabel(file.getName(),SwingConstants.CENTER);
		add(l,BorderLayout.CENTER);
		addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if(file.isDirectory()){
					if(file.getName().equals("..")){
						owner.showPath(file.getParentFile().getParent());
					}else{
						owner.showPath(file.getPath());
					}
				}
			}
			
		});
	}
    private File file;
    private ResourcesPanel owner;
    
    public File getFile(){
    	return file;
    }
}
